package com.ita.servlet.menu;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ita.factory.MServiceFactory;
import com.ita.pojo.Menu;
import com.ita.service.MenuService;
import com.ita.util.Constant;
import com.ita.util.JsonUtil;
import com.ita.vo.JsonResult;



@WebServlet("/sec/menu/goup")
public class UpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MenuService fService;

	
	public UpdateServlet() {
		super();
		fService = MServiceFactory.getMenuService();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		String id=request.getParameter("id");
		String mid = request.getParameter("mid");
		
		Menu food=fService.loadMenu(id, mid);
		
//		if(request.getSession().getAttribute("update_id")!=null){
//			request.getSession().removeAttribute("update_id");
//		}
		request.getSession().setAttribute("update_id", id);
	
		JsonResult jsonResult = new JsonResult();
		
		jsonResult.setCode(Constant.SUCEESS_CODE);
		jsonResult.setMsg(Constant.SUCCESS_MESSAGE);
		jsonResult.setData(food);

		String json = JsonUtil.getJsonFromObject(jsonResult);

		PrintWriter out = response.getWriter();
		out.write(json);
		out.flush();
		out.close();
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
